// https://www.luogu.com.cn/problem/P1091
#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
#define MAX_SIZE 10
#define MAXN 105

int n;
int a[MAXN];
int up[MAXN], dwn[MAXN];

int main() {
    scanf("%d", &n);
    rf(i, n) scanf("%d", a + i);

    for (int i = 1; i <= n; ++i) {
        up[i] = 1;
        for (int j = i - 1; j >= 1; --j) {
            if (a[i] > a[j]) up[i] = max(up[i], up[j] + 1);
        }
    }
    for (int i = n; i >= 1; --i) {
        dwn[i] = 1;
        for (int j = i + 1; j <= n; ++j) {
            if (a[i] > a[j]) dwn[i] = max(dwn[i], dwn[j] + 1);
        }
    }
    // rf(i, n) printf("%3d ", dwn[i]);
    int ans = 0;
    rf(i, n) ans = max(ans, up[i] + dwn[i] - 1);
    printf("%d", n - ans);
}
